package com.gexiaobao.pigeon.viewmodel.request

import androidx.lifecycle.MutableLiveData
import com.gexiaobao.pigeon.app.model.bean.MatchListResponse
import com.gexiaobao.pigeon.app.model.bean.RaceInfoResponse
import com.gexiaobao.pigeon.app.network.ListDataUiState
import com.gexiaobao.pigeon.app.network.apiService
import com.gexiaobao.pigeon.app.util.RxToast
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.request

/**
 * @Author      : hxw
 * @Date        : 2023/2/13 16:57
 * @Describe    :
 */
class RequestMatchViewModel : BaseViewModel() {

    /**  比赛列表  */
    var raceList: MutableLiveData<ListDataUiState<MatchListResponse.DataList>> = MutableLiveData()

//    /** 获取赛事信息 */
//    val raceInfoResult: MutableLiveData<RaceInfoResponse> = MutableLiveData()
//    fun getRaceInfo(raceId: Int, orgId: Int) {
//        request({ apiService.getRaceInfo(raceId, orgId) }, {
//            raceInfoResult.value = it
//        }, {
//            RxToast.warning(it.msg)
//        })
//    }

    fun getRace() {
        request({ apiService.getRace() }, {
            val listDataUiState = ListDataUiState(
                isSuccess = true, isRefresh = true, isEmpty = it.isEmpty(), isFirstEmpty = it.isEmpty(), listData = it.data
            )
            raceList.value = listDataUiState
        }, {
            val listDataUiState =
                ListDataUiState(isSuccess = false, isRefresh = false, errMessage = it.msg, listData = arrayListOf<MatchListResponse.DataList>())
            raceList.value = listDataUiState
        })
    }

}